package org.ant.gui.panes.ACtextpanel.listener;

import javax.swing.event.CaretEvent;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.UndoableEditEvent;
import javax.swing.event.UndoableEditListener;

import org.ant.gui.panes.ACtextpanel.ACTextPanel;


public class DocumentChangeListener implements CodeListener{
	private ACTextPanel acTextPanel;

	public DocumentChangeListener(ACTextPanel p){
		this.acTextPanel = p;
	}

	@Override
	public void changedUpdate(DocumentEvent e) {
	}

	@Override
	public void insertUpdate(DocumentEvent e) {
		acTextPanel.documentChange();
		CheckThread checkThread = new CheckThread(acTextPanel);
		checkThread.start();
		acTextPanel.updateLines();
	}

	@Override
	public void removeUpdate(DocumentEvent e) {
		acTextPanel.documentChange();
		CheckThread checkThread = new CheckThread(acTextPanel);
		checkThread.start();
		acTextPanel.updateLines();
	}

	@Override
	public void undoableEditHappened(UndoableEditEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void caretUpdate(CaretEvent e) {
		//System.out.println(e.getDot());
	}
}


class CheckThread extends Thread{
	ACTextPanel acTextPanel;

	public CheckThread(ACTextPanel acTextPanel) {
		this.acTextPanel = acTextPanel;
	}

	public void run() {
		acTextPanel.updateHighlights();
	}
}
